/**
 * Created by zhongb on 2017/4/11.
 */
var status = {"new":'新建',
    "sent":'已发货',
    "received":'已收货'};
require('layout/util');
require('jquery');
require('easyui');

//获取url参数
var asnCode = $.getUrlParam("noteCode");
var asnId = $.getUrlParam("asnId");
//页面数据初始化
dataInit(asnCode,asnId,status);
function dataInit(value,asnId) {
    $.ajax({
        url:'api/v1/p/wms/shipping/note/queryShelfCareDetail',
        type:'get',
        data:{
            noteCode:value
        },
        dataType:'json'
    })
        .done(function (result) {
            if(result.code == '200'){
                var data = result.data;
                var $firstTarget = $("#asn_info").find("span");
                var $secondTarget = $("#logistics_info").find("span");
                //元素赋值
                $firstTarget.eq(0).text(data.code);
                $firstTarget.eq(1).text(data.orderNo);
                $firstTarget.eq(2).text(data.entName);
                $firstTarget.eq(3).text(data.commitDt);
                $secondTarget.eq(0).text(data.destWarehouse);
                $secondTarget.eq(1).text(data.logticsName);
                $secondTarget.eq(2).text(data.expectedToOwmsTime);
                $secondTarget.eq(3).text(data.internationalLogisticsCarrier);
                $secondTarget.eq(4).text(data.internationalLogisticsNo);
                if(data.orderContainerVOS.length>0){
                    $("#container").show();
                    containerTableInit();
                    $("#container_table").datagrid({data:data.orderContainerVOS});
                }

                tableInit(asnId);
            }else{
                alert(result.message);
            }
        });
}
function containerTableInit() {
    $("#container_table").datagrid({
        border : false,
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 20, 50, 100 ],
        rownumbers:true,
        emptyMsg : "暂无数据",
        queryParams: {
            noteId: asnId
        },
        columns:[[
            {
                field : 'spec',
                title : '集装箱规格',
                width : '20%'
            },{
                field : 'code',
                title : '集装箱箱号',
                width : '20%'
            },{
                field : 'secretKey',
                title :'集装箱密钥',
                width : '40%'
            },{
                field : 'isFlooringLoad',
                title : '是否打板',
                width : '20%',
                formatter: function(value,row,index){
                    switch (value){
                        case'0': return '是';
                        case'1': return '否';
                        default:return data;
                    }
                }
            }]],
        onClickRow: function (rowIndex, rowData) {
            $(this).datagrid('unselectRow', rowIndex);
        }
    });
}
function tableInit(asnId) {
    $("#main_table").datagrid({
        url:'api/v1/p/mms/shipping/note/boxList',
        border : false,
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 20, 50, 100 ],
        rownumbers:true,
        emptyMsg : "暂无数据",
        queryParams: {
            noteId: asnId
        },
        columns:[[
            {
                field : 'code',
                title : '包裹码',
                width : '35%'
            },{
                field : 'boxCode',
                title : '箱号',
                width : '35%'
            },{
                field : 'skuNum',
                title :'SKU数量',
                width : '15%'
            },{
                field : 'goodsNum',
                title : '商品件数',
                width : '15%'
            }]],
        onClickRow: function (rowIndex, rowData) {
            $(this).datagrid('unselectRow', rowIndex);
        },
        loadFilter:function(data){
            if(data.code=='200'){
                return data.data;
            }else{
                alert(data.message);
            }
        }
    });
}